import { HttpException, Injectable } from '@nestjs/common';
import { PrismaService } from 'src/prisma/prisma.service';
import { UpdateUserDto } from './dto/update-user.dto';

@Injectable()
export class UserService {
  constructor(private prismaService: PrismaService) {}
  async findOne(id: number) {
    try {
      const res = await this.prismaService.user.findUnique({
        where: { id },
      });

      console.log(res);

      return res;
    } catch (error) {
      throw new HttpException('查询失败', 400);
    }
  }

  async update(id: number, data: UpdateUserDto) {
    console.log(data, id);
    try {
      const res = await this.prismaService.user.update({
        where: { id },
        data: {
          nickName: data.nickname,
          img: data.img,
          desc: data.desc,
        },
      });

      return res;
    } catch (error) {
      throw new HttpException('更新失败', 400);
    }
  }
}
